package com.accompany.controller;


import com.accompany.common.LoginUserThread;
import com.accompany.common.annotition.LoginUser;
import com.accompany.common.result.CommonResult;
import com.accompany.common.utils.UtilsTime;
import com.accompany.model.Patient;
import com.accompany.model.User;
import com.accompany.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 就诊人 前端控制器
 * </p>
 *
 * @author lfs
 * @since 2023-03-08
 */
@Api(tags = {"患者"})
@RestController
@RequestMapping("/patient")
public class PatientController {

    @Autowired
    PatientService service;

    @ApiOperation("新增患者")
    @PostMapping("/createPatient")
    public CommonResult createPatient(Patient patient){
        User user = LoginUserThread.get();
        if(patient!=null){
            return CommonResult.failed("陪诊人不能为空");
        } else {
            patient.setCerateTime(UtilsTime.getDayTime());
            patient.setCreateUserId(user.getId());
            boolean insert = service.save(patient);
            if(insert){
                return CommonResult.success(patient);
            } else {
                return CommonResult.failed("保存陪诊员失败");
            }
        }
    }

    @ApiOperation("获取患者列表")
    @GetMapping("/getPatients")
    public CommonResult getPatients(){
        User user = LoginUserThread.get();
        return CommonResult.success(service.getPatient(user.getId()));
    }

}
